<!DOCTYPE html>
<html lang="en">
<head>
<title>huangliusong</title>
<script type="text/javascript" src="./vue.js"></script>
</head>
 
<body>
	<div id="root">
		<input type="text" v-model="todoValue"/>
		<button @click="addClick">提交</button>
		<ul>
			<todo-item :content="item" 
					   :index="index"
					   v-for="(item,index) in list" @delete="deleteClick">
			</todo-item>
		</ul>
	</div>

	<script type="text/javascript">
		var TodoItem={
			props:['content','index'],
			template:"<li @click='deleteItem'>{{content}}</li>",
			methods:{
				deleteItem:function(){
					this.$emit("delete",this.index);
				}
			}
		}

		var app=new Vue({
			el:'#root',
			components:{
				TodoItem:TodoItem
			},
			data:{
				list:[],
				todoValue:''
			},
			methods:{
				addClick:function(){
					var date = new Date(); 
					this.list.push(this.todoValue+"               "+date);
					this.todoValue="";
				},
				deleteClick:function(index){
					//删除
					this.list.splice(index,1);
				}
			}
		})
	</script>
</body>

</html>